#define _CRT_SECURE_NO_WARNINGS 1

class Solution {
public:
    vector<vector<int>> ret;
    int n = 0;
    bitset<32> hash;
    vector<vector<int>> permute(vector<int>& nums) {
        n = nums.size();
        dfs(nums, vector<int>(), hash);
        return ret;
    }

    void dfs(vector<int>& nums, vector<int> tmp, bitset<32>& hash)
    {
        if (tmp.size() == n)
        {
            ret.push_back(tmp);
            return;
        }

        for (auto& e : nums)
        {
            if (hash.test(e + 10) == false)
            {
                hash.set(e + 10);
                tmp.push_back(e);
                dfs(nums, tmp, hash);
            }
            else
                continue;

            hash.reset(e + 10);
            tmp.pop_back();
        }
    }
};